/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.programacao.concorrente.monitor;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Implementação da atualização do monitor
 * @author afonso.rodrigues
 */
public class MonitorConsumer implements Runnable {

    private final Monitor monitor;

    public MonitorConsumer(Monitor monitor) {
        this.monitor = monitor;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (this) {
                
                this.monitor.atualizar();
                try {
                    wait(1000L);
                } catch (InterruptedException ex) {
                    Logger.getLogger(MonitorConsumer.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

    
    private void initMonitor() {
       new Thread(this).start();
    }

    public void init() {
        initMonitor();
    }
}
